package com.liufei1988.spring.bean.definition;

import com.liufei1988.spring.overview.domain.User;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Bean 别名示例
 *
 * @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
 * @since
 */
public class BeanAliasDemo {
    public static void main(String[] args){
        // 配置 XML 配置文件
        // 启动 Spring 应用上下文
        BeanFactory beanFactory = new ClassPathXmlApplicationContext("classpath:/META-INF/bean-definitions-context.xml");
        // 通过别名 xiaomage-user 获取曾用名 user 的 bean
        User user=beanFactory.getBean("user",User.class);
        User xiaomage=beanFactory.getBean("xiaomage",User.class);
        System.out.println("xiaomage-user 是否与 user Bean 相同：" + (user == xiaomage));
    }
}
